USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersContacts-Insert]    Script Date: 08/06/2012 21:20 ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: 08/06/2012 21:20
-- Description:	Insert record into table [dbo].[DealersContacts]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersContacts-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersContacts-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersContacts-Insert]
	/*@DealerContact_RowNumber int =Null OUTPUT , 
	@DealerContact_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@ContactType_ID uniqueidentifier =Null  , 
	@Contact_Value varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[DealersContacts](/*[DealerContact_ID], [Dealer_ID], [ContactType_ID], [Contact_Value]*/)
	VALUES     (/*@DealerContact_ID, @Dealer_ID, @ContactType_ID, @Contact_Value*/)

	/*SELECT @DealerContact_RowNumber = [DealerContact_RowNumber]
    FROM [dbo].[DealersContacts]
    WHERE  ( [DealerContact_ID] =@DealerContact_ID )
	AND  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [ContactType_ID] =@ContactType_ID )
	AND  ( [Contact_Value] =@Contact_Value )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersContacts-update]    Script Date: 08/06/2012 21:20 ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: 08/06/2012 21:20
-- Description:	Update record in table [dbo].[DealersContacts]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersContacts-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersContacts-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersContacts-update]
	/*@DealerContact_RowNumber int =Null OUTPUT , 
	@DealerContact_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@ContactType_ID uniqueidentifier =Null  , 
	@Contact_Value varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[DealersContacts] SET 
		/*[DealerContact_ID] =@DealerContact_ID, 
		[Dealer_ID] =@Dealer_ID, 
		[ContactType_ID] =@ContactType_ID, 
		[Contact_Value] =@Contact_Value*/
		/*WHERE ([DealerContact_ID] = @DealerContact_ID)*/
	/**/

	/*SELECT @DealerContact_RowNumber = [DealerContact_RowNumber]
    FROM [dbo].[DealersContacts]
	WHERE ([DealerContact_ID] = @DealerContact_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersContacts-Insert-Update]    Script Date: 08/06/2012 21:20 ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: 08/06/2012 21:20
-- Description:	Insert OR Update record into table [dbo].[DealersContacts]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersContacts-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersContacts-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersContacts-Insert-Update]
	/*@DealerContact_RowNumber int =Null OUTPUT , 
	@DealerContact_ID uniqueidentifier =Null  , 
	@Dealer_ID uniqueidentifier =Null  , 
	@ContactType_ID uniqueidentifier =Null  , 
	@Contact_Value varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[DealersContacts] 
					/*WHERE ([DealerContact_ID] = @DealerContact_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[DealersContacts](/*[DealerContact_ID], [Dealer_ID], [ContactType_ID], [Contact_Value]*/)
		VALUES     (/*@DealerContact_ID, @Dealer_ID, @ContactType_ID, @Contact_Value*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[DealersContacts] SET 
			/*[DealerContact_ID] =@DealerContact_ID, 
			[Dealer_ID] =@Dealer_ID, 
			[ContactType_ID] =@ContactType_ID, 
			[Contact_Value] =@Contact_Value*/
			/*WHERE ([DealerContact_ID] = @DealerContact_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @DealerContact_RowNumber = [DealerContact_RowNumber]
    FROM [dbo].[DealersContacts]
	WHERE ([DealerContact_ID] = @DealerContact_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersContacts-Delete]    Script Date: 08/06/2012 21:20 ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: 08/06/2012 21:20
-- Description:	delete records from table [dbo].[DealersContacts] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersContacts-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersContacts-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersContacts-Delete]
	/*@DealerContact_RowNumber int =null  , 
	@DealerContact_ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@ContactType_ID uniqueidentifier =null  , 
	@Contact_Value varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[DealersContacts]
	WHERE /*( [DealerContact_RowNumber] = ISNULL(@DealerContact_RowNumber, [DealerContact_RowNumber]) )
	AND ( [DealerContact_ID] = ISNULL(@DealerContact_ID, [DealerContact_ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [ContactType_ID] = ISNULL(@ContactType_ID, [ContactType_ID]) )
	AND ( [Contact_Value] like ISNULL(@Contact_Value, [Contact_Value]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[DealersContacts-Select]    Script Date: 08/06/2012 21:20 ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: 08/06/2012 21:20
-- Description:	select records from table [dbo].[DealersContacts] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[DealersContacts-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[DealersContacts-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[DealersContacts-Select]
	/*@DealerContact_RowNumber int =null  , 
	@DealerContact_ID uniqueidentifier =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@ContactType_ID uniqueidentifier =null  , 
	@Contact_Value varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[DealersContacts]
	WHERE /*( [DealerContact_RowNumber] = ISNULL(@DealerContact_RowNumber, [DealerContact_RowNumber]) )
	AND ( [DealerContact_ID] = ISNULL(@DealerContact_ID, [DealerContact_ID]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [ContactType_ID] = ISNULL(@ContactType_ID, [ContactType_ID]) )
	AND ( [Contact_Value] like ISNULL(@Contact_Value, [Contact_Value]) )*/
END
GO
-- =============================================
